<template>
	<view class="login-container">
		<view class="header">
			<view class="header-text">您好，欢迎使用 <br /> 中央仓采购系统</view>
			<view class="image-container">
				<image src="/static/images/login-bg.png"></image>
			</view>
		</view>
		<view class="form-container">
			<view class="form">
				<view class="form-item">
					<view class="label">手机号</view>
					<view class="value">
						<input v-model="mobile" type="number" placeholder="请输入手机号" />
					</view>
				</view>
				<view class="form-item">
					<view class="label">验证码</view>
					<view class="value flex">
						<input v-model="code" class="flex-1" type="number" placeholder="请输入验证码" />
						<view @click="sendCode" class="color-blue">
							<view v-if="isSend" class="flex">
								<uv-count-down @finish="isSend=false;" :time="60000" format="ss"></uv-count-down>秒重新获取
							</view>
							<view v-else>发送验证码</view>
						</view>
					</view>
				</view>
			</view>
			<view @click="sumbit" class="sumbit flex flex-items-center flex-justify-center "> 登录</view>
			<view class="weixin">
				<view class="tip  flex flex-justify-center">微信一键登录</view>
				<view class="flex flex-justify-center">
					<image src="/src/static/images/weixin-logo.png" mode=""></image>
				</view>
			</view>
			<view class="agreement flex flex-items-center flex-justify-center ">
				<uv-checkbox-group shape="circle" class="checkboxGroup" style="">
					<uv-checkbox label="" name="1"></uv-checkbox>
				</uv-checkbox-group>
				<view class="tip">我已阅读并同意 <text class="color-blue">《用户协议》</text> </view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onReachBottom,
		onPullDownRefresh,
		onShow
	} from '@dcloudio/uni-app';
	import {
		useAccountStore
	} from '@/store';
	import {
		sentMessage,
		login
	} from '@/api/login.js';
	const accountStore = useAccountStore();
	let code = ref("");
	let mobile = ref("");
	let isSend = ref(false);
	async function sendCode() {
		let res = await sentMessage({
			mobile: mobile.value,
			scene: 1,
		});
		if (res.code == 0) {
			uni.showToast({
				title: "验证码发送成功",
				icon: 'none'
			});
			isSend.value = true;
		}
	}
	// onLoad(() => {
	// 	window.location.replace(
	// 	`https://open.weixin.qq.com/connect/oauth2/authorize?
	// 	appid=wxe746e0c241cf42f8&
	// 	redirect_uri=${encodeURI('https://wepay.yunshucs.cn/')}
	// 	&
	// 	response_type=code
	// 	&
	// 	scope=snsapi_base
	// 	&
	// 	state=oauth2
	// 	#wechat_redirect
	// 	`);
	// }) 
	function sumbit() {
		if (!code.value) {
			uni.showToast({
				title: "验证码不能为空",
				icon: 'none'
			});
			return
		}
		if (!mobile.value) {
			uni.showToast({
				title: "手机号不能为空",
				icon: 'none'
			});
			return
		}
		accountStore.login({
			code: code.value,
			mobile: mobile.value
		}).then(res => {
			uni.navigateTo({
				url: '/pages/login/pages/centralWarehouse/index'
			})
		})
	}
</script>

<style lang="scss">
	:deep(.uv-count-down__text) {
		color: #60a5fa !important;
	}

	@import 'index.scss';
</style>